package LeetCode热题HOT100;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class p46全排列 {
    List<List<Integer>> res=new ArrayList<>();
    public List<List<Integer>> permute(int[] nums) {
        if (nums.length==0) {
            return res;
        }

        LinkedList<Integer> oneRes=new LinkedList<>();
        backTrack(nums,oneRes);

        return res;

    }

    private void backTrack(int[] nums, LinkedList<Integer> oneRes) {
        if (oneRes.size()==nums.length) {
            res.add(new ArrayList<>(oneRes));
            return;
        }
        for (int i = 0; i <nums.length; i++) {
            if (oneRes.contains(nums[i])) {
                continue;
            }
            oneRes.add(nums[i]);
            backTrack(nums,oneRes);
            oneRes.removeLast();
        }
    }
}
